/**
 *  created by lllwx
 *  Date: 2021/6/1
 *  Time: 11:34 上午
 *  Version: 1.0
 *  For: vue-cli配置文件
 */
const path = require('path');
const tailwind = require('tailwindcss');
const autoprefixer = require('autoprefixer');
const AntdDayjsWebpackPlugin = require('antd-dayjs-webpack-plugin');

const resolve = (dir) => path.join(__dirname, dir);

module.exports = {
  productionSourceMap: process.env.VUE_APP_PRO === 'false',
  publicPath: '/', // 部署应用包时的基本 URL
  assetsDir: '.',
  // 出口文件
  outputDir: 'dist',
  css: {
    loaderOptions: {
      postcss: {
        plugins: [
          tailwind,
          autoprefixer,
        ],
      },
      less: {
        lessOptions: {
          javascriptEnabled: true,
        },
      },
    },
  },
  configureWebpack: (config) => {
    config.plugins.push(new AntdDayjsWebpackPlugin({
      preset: 'antdv3',
    }));
  },
  chainWebpack: (config) => {
    config.resolve.alias.set('@', resolve('src'))
      .set('@c', resolve('src/components'))
      .set('@u', resolve('src/vca'))
      .set('vca', resolve('../../vca'))
      .set('common', resolve('../../common'));

    // 配置svg
    config.module
      .rule('svg')
      .exclude
      .add(resolve('src/icons/svg'))
      .end();
    config.module
      .rule('icons')
      .test(/\.svg$/)
      .include.add(resolve('src/icons/svg'))
      .end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({
        symbolId: 'icon-[name]',
      })
      .end();

    config.plugin('html')
      .tap((args) => {
        args[0].title = 'vue2-template';
        return args;
      });
  },
  devServer: {
    port: 8911,
    disableHostCheck: true,
  },
};
